package tichu_project252.CardClasses;
 /**
     * This class implements the cards of the game.
     *
     * <p>Basic element of the game is a Card. The Cards are simple Cards and
     * special Cards. </p>
     *
     * <p> <b> Invariants: </b> The int representation of the cards is a number
     * from 1 to 14. (1 -> Mahjong, 2-> "2', 11 -> "J")
     *
     * @author Alexandra Barka, ΑΜ: 2867, login : barka.
     * @author Euaggelia Petauraki AM: 2875 login: petavraki.
     * @version %I%, %G%
     *
     */
public abstract class Card {

   
    protected int intRepr;                     //The int representation of the card
    protected String strRepr;               // The string representation of the card
    protected String pathImage;               // The path of the image of the card
    private boolean isSelected;             // Whether the card is selected or not.

    /**
     * Constructs a new card given the number and the name of the Card.
     *
     * <p><b>Constructor: </b> Card(int intRepr, String strRepr) </p>
     *
     * <p><b>Precondition: </b> the number and name of the card are valid. </p>
     * <p><b>Postcondition: </b> Constructs a valid tichu card </p>
     *
     *
     * @param num The number of the card
     * @param str The string representation of the card
     */
    Card(int intRepr, String strRepr) throws Exception {
        if ((intRepr >= 1 || intRepr < 15) && strRepr != null) {
            this.intRepr = intRepr;
            this.strRepr = strRepr;
        } else {
            throw new Exception("Not that kind of card existed.");
        }
        isSelected = false;
    }

    /**
     * Constructs a new card given the name of the Card.
     *
     * <p><b>Constructor: </b> Card(String strRepr) </p>
     *
     * <p><b>Precondition: </b> the name of the card is valid. </p>
     * <p><b>Postcondition: </b> Constructs a valid tichu card </p>
     *
     *
     * @param num The number of the card
     * @param str The string representation of the card
     */
    Card(String strRepr) throws Exception {
        if (strRepr != null) {
            this.strRepr = strRepr;
        } else {
            throw new Exception("Not a valid name of card");
        }
    }

    /**
     * getSuit returns the suit of the card if the card is simpleCard. This
     * method is implemented in subclasses of the Card. If the Card is
     * simpleCard we return the suit of the card else we return null
     *
     * <p> <b> Accessor: </b> getSuit() </p> <p><b> Precondition: </b> The card
     * has suit </p> <p> <b> Postcondition: </b> Returns the suit of the
     * card.</p>
     *
     * @return The suit of the card
     */
    public abstract String getSuit();

    /**
     * getintRepr returns the int representation of the card.
     *
     * Every simple card and the Mahjong has a int representation. This function
     * returns this number.
     *
     * <p> <b> Accessor: </b> getintRepr() </p> <p><b> Precondition: </b> The
     * intRepr is between 1-14 </p> <p> <b> Postcondition: </b> Returns the int
     * Representation of the card</p>
     *
     * @return intRepr the int representation of the card
     */
    public int getintRepr() {
        return intRepr;
    }
    
    public void setintRepr(int i) {
        this.intRepr = i;
    }

    /**
     * getistringRepr returns the string representation of the card.
     *
     * Every card has a string representation. This function returns this
     * string.
     *
     * <p> <b> Accessor: </b> getstringRepr() </p> <p><b> Precondition: </b> The
     * name of the card isn't null </p> <p> <b> Postcondition: </b> Returns the
     * string Representation of the card</p>
     *
     * @return strRepr the string representation of the card
     */
    public String getstringRepr() {
        return strRepr;
    }

    /**
     * LoadImage sets the path of the image.
     *
     * Every card has an image. This functions set the path of the image. <p>
     * <b> Transformer: </b> LoadImage(String pathImage) </p> <p><b>
     * Precondition: </b> The path of the iamge is not null </p> <p> <b>
     * Postcondition: </b> Sets the image for the Card</p>
     *
     * @param pathImage The path of the image.
     * @throws Exception Throws an exception if the image is invalid.
     */
    
    
    public void LoadImage(String pathImage) throws Exception {
        if (pathImage != null) {
            this.pathImage = pathImage;
        } else {
            throw new Exception("Invalid Image");
        }
    }

    /**
     * This function returns the path of the image.
     *
     * <p> <b> Accessor: </b> getImage() </p> 
     * <p><b> Precondition: </b> The path is not null </p> 
     * <p> <b> Postcondition: </b> Returns  a valid path.</p>
     *
     * @return pathImage Returns the path of the image
     * 
     */
    
    public String getImage() {
        return pathImage;
    }

    /**
     * This function returns whether an image is selected.
     * 
     * The user chooses images that he can play. This function returns is an image is selected.
     *
     * <p> <b> Accessor: </b> getSelectedr() </p> 
     * <p><b> Precondition: </b>  </p> 
     * <p> <b> Postcondition: </b> Returns if the card is selected or not</p>
     *
     * @return isSelected 
     */
    
    public boolean getSelected() {
        return isSelected;
    }
 
    /**
     *  Sets if a card is selected or not.
     * 
     * <p> <b> Transformer: </b> setSelected(boolean isSelected) </p> 
     * <p><b> Precondition: </b> </p> 
     * <p> <b> Postcondition: </b> Becomes true if a card is selected or false if its not.</p>
     *
     * @param isSelected whether a card is selected
     */
    public void setSelected(boolean isSelected) {
        this.isSelected = isSelected;
    }
    
    /**
     * Returns the representation of the card in a string.
     * 
     * <p> <b> Accessor: </b> toString()  </p> 
     * <p><b> Precondition: </b> The card is correctly constructed.</p> 
     * <p> <b> Postcondition: </b> Returns a string with the intRepr and strRepr.</p>
     *
     * @return Therepresentation of the card
     */

    @Override
    public String toString() {
        String s = "Int Representation: " + intRepr + "String Representation:  " + strRepr;
        return s;
    }
}
